﻿using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Infragistics.Composite.Wpf.Docking;
using Infragistics.Composite.Wpf.Proxies.Docking;
using Infragistics.Windows.DockManager;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Composite.Wpf.Regions;

namespace Infragistics.Composite.Wpf.SampleBrowser
{
    public partial class ShellWindow : Window
    {
        int _newViewCounter = 0;

        public ShellWindow()
        {
            InitializeComponent();
        }

        void OnRemoveActiveViewButtonClick(object sender, RoutedEventArgs e)
        {
            IRegionManager regionMgr = RegionManager.GetRegionManager(this.dockManager);
            IRegion region = regionMgr.Regions[Infragistics.Composite.Wpf.Samples.Infrastructure.RegionNames.DockingAreaRegion];
            object activeView = region.ActiveViews.FirstOrDefault();
            if (activeView != null)
                region.Remove(activeView);
        }

        void OnAddNewViewButtonClick(object sender, RoutedEventArgs e)
        {
            TextBlock view = new TextBlock { Text = Properties.Strings.ShellWindow_DynamicView_Text };

            Style contentPaneProxyStyle = new Style(typeof(ContentPaneProxy));
            string header = String.Format(Properties.Strings.ShellWindow_DynamicView_FormattedHeader, ++_newViewCounter);
            contentPaneProxyStyle.Setters.Add(new Setter(ContentPane.HeaderProperty, header));
            XamDockManagerSettings.SetContentPaneProxyStyle(view, contentPaneProxyStyle);

            XamDockManagerSettings.SetSplitPaneName(view, "staticSplitPane");

            IRegionManager regionMgr = RegionManager.GetRegionManager(this.dockManager);
            IRegion region = regionMgr.Regions[Infragistics.Composite.Wpf.Samples.Infrastructure.RegionNames.DockingAreaRegion];
            region.Add(view);
        }
    }
}